package cn.zwt.wolf.service.position;

import cn.zwt.wolf.domain.content.Content;
import cn.zwt.wolf.domain.position.PositionItem;
import cn.zwt.wolf.repository.position.PositionItemRepository;
import cn.zwt.wolf.util.SearchUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Created by zhangwt on 16-3-13.
 */
@Service
public class PositionItemService {
    @Autowired
    private PositionItemRepository positionItemRepository;
    @Autowired
    private SearchUtil searchUtil;
    private Logger logger = LoggerFactory.getLogger(PositionService.class);

    public void saveOrUpdate(PositionItem positionItem){
        positionItemRepository.save(positionItem);
    }

    public PositionItem changeContentToPositionItem(Content p , PositionItem item, String positionCode){
        if (item == null) {
            item = new PositionItem();

//            item.set(p.getId());
//            item.setSid(p.getSid());
//            item.setEditTitle(p.getTitle());
//            item.setEditIcon(p.getIcon1());
//            item.setEditIndex(0);
            item.setLinkType(1);
//            item.setBeginValidDate(null);
//            item.setEndValidDate(null);
            item.setCreateTime(new Date());
            item.setValidTime(new Date());
        }
        item.setValidTime(new Date());
        item.setPositionCode(positionCode);
        item.setItemTitle(p.getTitle());
        item.setItemId(p.getId());
        item.setTitle(p.getTitle());
        item.setItemUpdateTime(p.getUpdateTime());
        item.setItemDuration(p.getDuration());
        item.setItemEpisode(p.getEpisode());
        item.setItemEpisodeCount(p.getEpisodeCount());
        item.setItemIndex(p.getRankIndex());
        item.setItemScore(p.getScore());
        item.setItemVideoType(p.getVideoType());
        item.setType(p.getType());
//        item.setContentType(p.getContentType());
//        item.setYear(p.getYear());
//        item.setCast(p.getCast());
//        item.setActor(p.getActor());
//        item.setDirector(p.getDirector());
//        item.setHost(p.getHost());
//        item.setInformation(p.getInformation());
//        item.setDuration(p.getDuration());
//        item.setTags(p.getTags());
//        item.setArea(p.getArea());
//        item.setEpstitle(p.getEpstitle());
        item.setIcon1(p.getIcon1());
        item.setIcon2(p.getIcon2());
//        item.setIcon3(p.getIcon3());
//        item.setImage1(p.getImage1());
//        item.setImage2(p.getImage2());
//        item.setImage3(p.getImage3());
//        item.setEpisodeCount(p.getEpisodeCount());
        item.setIndex(p.getRankIndex());
        item.setStatus(p.getStatus());
//        item.setVideoType(p.getVideoType());
//        item.setExternalType(p.getExternalType());
//        item.setPicList(p.getPicList());
//        item.setScore(p.getScore());
//        item.setEpisode(p.getEpisode());
//        item.setImage(p.getImage());
//        item.setParentId(p.getParentId());
//        item.setParentCode(p.getParentCode());
//        item.setExternalId(p.getExternalId());
//        item.setDoubanId(p.getDoubanId());
//        item.setTagsCode(p.getTagsCode());
//        item.setRank(p.getRank());
        // TODO 找到计算权值的方法
//		item.setOrderPriority(0);
//        item.setAreaCode(p.getAreaCode());
//        item.setTvmao(p.getTvmao());
//        item.setImpression(p.getImpression());
        item.setCreateTime(p.getCreateTime());
        item.setUpdateTime(new Date());
        item.setPublishTime(p.getPublishTime());
        return item;
    }
}
